/*
 * LinearInterpolationModel.cpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   LinearInterpolationModel.cpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   11 feb 2013
 */

#include <stdexcept>
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>

#include "LinearInterpolationThermistor.hpp"

#include "LinearInterpolationModel.hpp"


using boost::shared_ptr;
using boost::make_shared;

namespace tltgen {

  LinearInterpolationModel::LinearInterpolationModel() { }

  LinearInterpolationModel::~LinearInterpolationModel() { }

  std::string LinearInterpolationModel::getName() const
  {
    return "Linear interpolation";
  }
  unsigned int LinearInterpolationModel::getMinNbValues() const
  {
    return 2;
  }
  
  shared_ptr<Thermistor> LinearInterpolationModel::generate(const shared_ptr<ThermistorTable>& thermistorTable, const LeastSquaresSolver& solver)
  {
    return make_shared<LinearInterpolationThermistor>(thermistorTable);
  }

  unsigned int LinearInterpolationModel::getNbParameters() const
  {
    return 0;
  }

  std::string LinearInterpolationModel::getParameterName(unsigned int pi) const
  {
    throw std::invalid_argument("Invalid parameter index specified.");
  }

  ThermistorModel::ParameterType LinearInterpolationModel::getParameterType(unsigned int pi) const
  {
    throw std::invalid_argument("Invalid parameter index specified.");
  }

  void LinearInterpolationModel::getInitialGuess(double *guess) const
  { }
  
  bool LinearInterpolationModel::isParameterFixed(unsigned int pi) const
  {
    throw std::invalid_argument(boost::lexical_cast<std::string>(pi) + " is not a valid parameter index.");
  }

  bool LinearInterpolationModel::hasParameterLowerBound(unsigned int pi) const
  {
    throw std::invalid_argument(boost::lexical_cast<std::string>(pi) + " is not a valid parameter index");
  }

  double LinearInterpolationModel::getParameterLowerBound(unsigned int pi) const
  {
    throw std::invalid_argument(boost::lexical_cast<std::string>(pi) + " is not a valid parameter index.");
  }

  bool LinearInterpolationModel::hasParameterUpperBound(unsigned int pi) const
  {
    throw std::invalid_argument(boost::lexical_cast<std::string>(pi) + " is not a valid parameter index.");
  }
  double LinearInterpolationModel::getParameterUpperBound(unsigned int pi) const
  {
    throw std::invalid_argument(boost::lexical_cast<std::string>(pi) + " is not a valid parameter index.");
  }

  void LinearInterpolationModel::applyModelFunction(const ThermistorTable* thermistorTable, const double *params, double *residues) const
  {
    throw std::runtime_error("There is no model function for a linear interpolation model.");
  }

  void LinearInterpolationModel::applyModelDerivative(const ThermistorTable* thermistorTable, const double *params, double *jacobian) const
  {
    throw std::runtime_error("There is no derivative model function for a linear interpolation model.");
  }

}
